<template>
  <div>
    <el-card shadow="never">
      <div slot="header"><div class="demo-basic--circle">
        <div class="block"><el-avatar :size="100" :src="imgs"></el-avatar></div>
      </div><span style="margin-left: 15px">头像修改</span></div>
      <div style="min-height:30vh;width:30%">
        <el-form ref="form" label-width="80px">
          <el-upload
              class="upload-demo"
              ref="upload"
              :auto-upload="false"
              :http-request="upLoadFile"
              :multiple="multiple"
              :limit="Number(1)"
              drag
              action=""
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
            <div class="el-upload__tip" slot="tip">只能上传jpg/png文件，且不超过3MB</div>
          </el-upload>
          <div align="center">
            <el-button
                type="success"
                size="small"
                @click="onSubmit()"
            >确认</el-button>
          </div>
        </el-form>
      </div>
    </el-card>
  </div>
</template>
<script>
import img from "../../assets/imgs/timg.png"
export default {
  data() {
    return {
      imgs:img,
      multiple:true,
    };
  },
  methods: {
    upLoadFile(file){
      this.formData.append("files",file.file)
    },
    onSubmit() {
      this.formData = new FormData();
      this.formData.append("uid",sessionStorage.getItem(sessionStorage.getItem("user_label")+"uid"));
      this.$refs.upload.submit();
      this.$axios.post(this.$axios.defaults.baseURL+"/student/setheadimg",this.formData,{
        headers: {'Content-Type': 'multipart/form-data'
        }}).then(res => {
        if (res.status) {
          this.$message.success(res.data.msg);
          sessionStorage.setItem(sessionStorage.getItem("user_label")+"img",res.data.toux);
          setTimeout(() => {
            if(res.status){
              this.$router.go(0);
            }
          }, 1500);
        } else {
          this.$message.error(res.data.msg);
        }
      })
    },
  },
};
</script>
<style scoped>

</style>